﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows.Forms;

namespace ShopCD.BusinessLogic
{
    class bl_CayDM
    {
        //
        Form frm;
        ShopCD.AccessData.AccessData con;
        string sql;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="f"></param>
        public bl_CayDM(ShopCD.GUI.frm_CayDM f)
        {
            con = new ShopCD.AccessData.AccessData();
            frm = f;
        }

        /// <summary>
        /// 
        /// </summary>
        public void Show()
        {
            sql = "Select * from Danhmuc";
            con.Open();

            DataTable tb_DM = con.Get_DataTable(sql);
            TreeView tv = (TreeView)frm.Controls["tv_DanhMuc"];
            foreach (DataRow dr in tb_DM.Rows)
            {
                TreeNode Node_P = new TreeNode();
                Node_P.Text = dr["TenDM"].ToString();
                Node_P.Tag = dr["MaDM"].ToString();
                sql = "Select * From ShopCD Where MaDM = '" + dr["MaDM"].ToString() + "'";
                DataTable tb_CD = con.Get_DataTable(sql);
                foreach (DataRow row in tb_CD.Rows)
                {
                    TreeNode Node_C = new TreeNode();
                    Node_C.Text = row["TenLoai"].ToString();
                    Node_C.Tag = row["MaCD"].ToString();
                    Node_P.Nodes.Add(Node_C);
                }
                tv.Nodes.Add(Node_P);
            }

            con.Close();
        }

        /// <summary>
        /// gdfg
        /// </summary>
        /// <param name="MaDM">Tham doi</param>
        public void View_Node(string MaDM)
        {
            sql = "Select * From ShopCD Where MaDM = '" + MaDM + "'";
            con.Open();
            DataTable tb_Shop = con.Get_DataTable(sql);
            con.Close();
            ListView lv = (ListView)frm.Controls["lv_DM"];
            lv.Items.Clear();
            foreach (DataRow row in tb_Shop.Rows)
            {
                ListViewItem it = new ListViewItem();
                it.Text = row["TenLoai"].ToString();
                ListViewItem.ListViewSubItem it_sub = new ListViewItem.ListViewSubItem();
                it_sub.Text = row["MaCD"].ToString();
                it.SubItems.Add(it_sub);
                lv.Items.Add(it);
            }
        }
    }
}
